{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 11: Working With Common Cloud Sources"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Amazon S3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3_file_path = 's3://polars-cookbook-demo-yk/titanic_dataset.csv'\n",
    "df = pl.read_csv(s3_file_path)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import s3fs \n",
    "\n",
    "fs = s3fs.S3FileSystem()\n",
    "\n",
    "s3_parquet_file_path = 's3://polars-cookbook-demo-yk/titanic_dataset.parquet'\n",
    "\n",
    "with fs.open(s3_parquet_file_path, mode='wb') as f:\n",
    "    df.write_parquet(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "storage_options= {\n",
    "    'aws_access_key_id': 'YOUR_ACCESS_KEY_ID',\n",
    "    'aws_secret_access_key': 'YOUR_SECRET_ACCESS_KEY',\n",
    "    'aws_region': 'us-east-1'\n",
    "}\n",
    "\n",
    "lf = pl.scan_parquet(s3_parquet_file_path, storage_options=storage_options)\n",
    "lf.head().collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import s3fs \n",
    "\n",
    "fs = s3fs.S3FileSystem(\n",
    "    key='YOUR_ACCESS_KEY_ID',\n",
    "    secret='YOUR_SECRET_ACCESS_KEY'\n",
    ")\n",
    "\n",
    "with fs.open(s3_parquet_file_path, mode='wb') as f:\n",
    "    df.write_parquet(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>8</td><td>0</td><td>3</td><td>&quot;Palsson, Maste…</td><td>&quot;male&quot;</td><td>2.0</td><td>3</td><td>1</td><td>&quot;349909&quot;</td><td>21.075</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>9</td><td>1</td><td>3</td><td>&quot;Johnson, Mrs. …</td><td>&quot;female&quot;</td><td>27.0</td><td>0</td><td>2</td><td>&quot;347742&quot;</td><td>11.1333</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>10</td><td>1</td><td>2</td><td>&quot;Nasser, Mrs. N…</td><td>&quot;female&quot;</td><td>14.0</td><td>1</td><td>0</td><td>&quot;237736&quot;</td><td>30.0708</td><td>null</td><td>&quot;C&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 8           ┆ 0        ┆ 3      ┆ Palsson, Master.  ┆ … ┆ 349909    ┆ 21.075  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Gosta Leonard     ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 9           ┆ 1        ┆ 3      ┆ Johnson, Mrs.     ┆ … ┆ 347742    ┆ 11.1333 ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Oscar W           ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Elisabeth…       ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 10          ┆ 1        ┆ 2      ┆ Nasser, Mrs.      ┆ … ┆ 237736    ┆ 30.0708 ┆ null  ┆ C        │\n",
       "│             ┆          ┆        ┆ Nicholas (Adele   ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ Ach…              ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyarrow.dataset as ds\n",
    "\n",
    "dataset = ds.dataset(s3_parquet_file_path, format='parquet', filesystem=fs)\n",
    "df = (\n",
    "    pl.scan_pyarrow_dataset(dataset)\n",
    "    .filter(pl.col('Age') <= 30)\n",
    "    .collect()\n",
    ")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Azure Blog Storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "storage_options={\n",
    "    'account_name': 'YOUR_ACCOUNT_NAME', \n",
    "    'access_key': 'YOUR_ACCOUNT_KEY',\n",
    "    'client_id': 'YOUR_CLIENT_ID',\n",
    "    'client_secret': 'YOUR_CLIENT_SECRET',\n",
    "    'tenant_id': 'YOUR_TENANT_ID'\n",
    "}\n",
    "\n",
    "blob_csv_file_path = 'az://demo/titanic_dataset.csv'\n",
    "df = pl.read_csv(blob_csv_file_path, storage_options=storage_options) \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import adlfs \n",
    "\n",
    "fs = adlfs.AzureBlobFileSystem(\n",
    "    account_name='YOUR_ACCOUNT_NAME', \n",
    "    account_key='YOUR_ACCOUNT_KEY'\n",
    ")\n",
    "\n",
    "blob_parquet_file_path = 'az://demo/titanic_dataset.parquet'\n",
    "\n",
    "with fs.open(blob_parquet_file_path, mode='wb') as f:\n",
    "    df.write_parquet(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lf = pl.scan_parquet(blob_parquet_file_path, storage_options=storage_options)\n",
    "lf.head().collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>8</td><td>0</td><td>3</td><td>&quot;Palsson, Maste…</td><td>&quot;male&quot;</td><td>2.0</td><td>3</td><td>1</td><td>&quot;349909&quot;</td><td>21.075</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>9</td><td>1</td><td>3</td><td>&quot;Johnson, Mrs. …</td><td>&quot;female&quot;</td><td>27.0</td><td>0</td><td>2</td><td>&quot;347742&quot;</td><td>11.1333</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>10</td><td>1</td><td>2</td><td>&quot;Nasser, Mrs. N…</td><td>&quot;female&quot;</td><td>14.0</td><td>1</td><td>0</td><td>&quot;237736&quot;</td><td>30.0708</td><td>null</td><td>&quot;C&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 8           ┆ 0        ┆ 3      ┆ Palsson, Master.  ┆ … ┆ 349909    ┆ 21.075  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Gosta Leonard     ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 9           ┆ 1        ┆ 3      ┆ Johnson, Mrs.     ┆ … ┆ 347742    ┆ 11.1333 ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Oscar W           ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Elisabeth…       ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 10          ┆ 1        ┆ 2      ┆ Nasser, Mrs.      ┆ … ┆ 237736    ┆ 30.0708 ┆ null  ┆ C        │\n",
       "│             ┆          ┆        ┆ Nicholas (Adele   ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ Ach…              ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyarrow.dataset as ds\n",
    "\n",
    "dataset = ds.dataset(\n",
    "    blob_parquet_file_path, \n",
    "    filesystem=fs,\n",
    "    format='parquet')\n",
    "\n",
    "df = (\n",
    "    pl.scan_pyarrow_dataset(dataset)\n",
    "    .filter(pl.col('Age') <= 30)\n",
    "    .collect()\n",
    ")\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "os.environ['AZURE_STORAGE_ACCOUNT_NAME'] = 'YOUR_ACCOUNT_NAME'\n",
    "os.environ['AZURE_STORAGE_ACCOUNT_KEY'] = 'YOUR_ACCOUNT_KEY'\n",
    "\n",
    "(\n",
    "    pl.read_csv(blob_csv_file_path, storage_options=storage_options)\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There is more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 10)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>I138884</th><th>C241288</th><th>Female</th><th>28</th><th>Clothing</th><th>5</th><th>1500.4</th><th>Credit Card</th><th>5/8/2022</th><th>Kanyon</th></tr><tr><td>str</td><td>str</td><td>str</td><td>i64</td><td>str</td><td>i64</td><td>f64</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;I317333&quot;</td><td>&quot;C111565&quot;</td><td>&quot;Male&quot;</td><td>21</td><td>&quot;Shoes&quot;</td><td>3</td><td>1800.51</td><td>&quot;Debit Card&quot;</td><td>&quot;12/12/2021&quot;</td><td>&quot;Forum Istanbul…</td></tr><tr><td>&quot;I127801&quot;</td><td>&quot;C266599&quot;</td><td>&quot;Male&quot;</td><td>20</td><td>&quot;Clothing&quot;</td><td>1</td><td>300.08</td><td>&quot;Cash&quot;</td><td>&quot;9/11/2021&quot;</td><td>&quot;Metrocity&quot;</td></tr><tr><td>&quot;I173702&quot;</td><td>&quot;C988172&quot;</td><td>&quot;Female&quot;</td><td>66</td><td>&quot;Shoes&quot;</td><td>5</td><td>3000.85</td><td>&quot;Credit Card&quot;</td><td>&quot;16/05/2021&quot;</td><td>&quot;Metropol AVM&quot;</td></tr><tr><td>&quot;I337046&quot;</td><td>&quot;C189076&quot;</td><td>&quot;Female&quot;</td><td>53</td><td>&quot;Books&quot;</td><td>4</td><td>60.6</td><td>&quot;Cash&quot;</td><td>&quot;24/10/2021&quot;</td><td>&quot;Kanyon&quot;</td></tr><tr><td>&quot;I227836&quot;</td><td>&quot;C657758&quot;</td><td>&quot;Female&quot;</td><td>28</td><td>&quot;Clothing&quot;</td><td>5</td><td>1500.4</td><td>&quot;Credit Card&quot;</td><td>&quot;24/05/2022&quot;</td><td>&quot;Forum Istanbul…</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 10)\n",
       "┌─────────┬─────────┬────────┬─────┬───┬─────────┬─────────────┬────────────┬────────────────┐\n",
       "│ I138884 ┆ C241288 ┆ Female ┆ 28  ┆ … ┆ 1500.4  ┆ Credit Card ┆ 5/8/2022   ┆ Kanyon         │\n",
       "│ ---     ┆ ---     ┆ ---    ┆ --- ┆   ┆ ---     ┆ ---         ┆ ---        ┆ ---            │\n",
       "│ str     ┆ str     ┆ str    ┆ i64 ┆   ┆ f64     ┆ str         ┆ str        ┆ str            │\n",
       "╞═════════╪═════════╪════════╪═════╪═══╪═════════╪═════════════╪════════════╪════════════════╡\n",
       "│ I317333 ┆ C111565 ┆ Male   ┆ 21  ┆ … ┆ 1800.51 ┆ Debit Card  ┆ 12/12/2021 ┆ Forum Istanbul │\n",
       "│ I127801 ┆ C266599 ┆ Male   ┆ 20  ┆ … ┆ 300.08  ┆ Cash        ┆ 9/11/2021  ┆ Metrocity      │\n",
       "│ I173702 ┆ C988172 ┆ Female ┆ 66  ┆ … ┆ 3000.85 ┆ Credit Card ┆ 16/05/2021 ┆ Metropol AVM   │\n",
       "│ I337046 ┆ C189076 ┆ Female ┆ 53  ┆ … ┆ 60.6    ┆ Cash        ┆ 24/10/2021 ┆ Kanyon         │\n",
       "│ I227836 ┆ C657758 ┆ Female ┆ 28  ┆ … ┆ 1500.4  ┆ Credit Card ┆ 24/05/2022 ┆ Forum Istanbul │\n",
       "└─────────┴─────────┴────────┴─────┴───┴─────────┴─────────────┴────────────┴────────────────┘"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "storage_options['account_name'] = 'YOUR_ADLS_ACCOUNT_NAME'\n",
    "storage_options['account_key'] = 'YOUR_ADLS_ACCOUNT_KEY'\n",
    "\n",
    "df = pl.read_csv(blob_csv_file_path, storage_options=storage_options) \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Google Cloud Storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gcs_csv_file_path = 'gs://polars_cookbook_demo_yk/titanic_dataset.csv'\n",
    "\n",
    "df = pl.read_csv(gcs_csv_file_path)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "credentials_file_path = 'YOUR_FILE_NAME.json'\n",
    "storage_options = {'token': credentials_file_path}\n",
    "df = pl.read_csv(gcs_csv_file_path, storage_options=storage_options)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "def read_json_into_dict(file_path):   \n",
    "    try:  \n",
    "        with open(file_path) as file:\n",
    "            dict = json.load(file)\n",
    "            return dict\n",
    "    except Exception as err:\n",
    "        raise err\n",
    "\n",
    "storage_options = read_json_into_dict(credentials_file_path)\n",
    "\n",
    "df = pl.read_csv(gcs_csv_file_path, storage_options=storage_options)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import gcsfs\n",
    "\n",
    "fs = gcsfs.GCSFileSystem()\n",
    "\n",
    "gcs_parquet_file_path = 'gs://polars_cookbook_demo_yk/titanic_dataset.parquet'\n",
    "\n",
    "with fs.open(gcs_parquet_file_path, mode='wb') as f:\n",
    "    df.write_parquet(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "import gcsfs\n",
    "\n",
    "fs = gcsfs.GCSFileSystem(\n",
    "    token=credentials_file_path\n",
    ")\n",
    "\n",
    "with fs.open(gcs_parquet_file_path, mode='wb') as f:\n",
    "    df.write_parquet(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>8</td><td>0</td><td>3</td><td>&quot;Palsson, Maste…</td><td>&quot;male&quot;</td><td>2.0</td><td>3</td><td>1</td><td>&quot;349909&quot;</td><td>21.075</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>9</td><td>1</td><td>3</td><td>&quot;Johnson, Mrs. …</td><td>&quot;female&quot;</td><td>27.0</td><td>0</td><td>2</td><td>&quot;347742&quot;</td><td>11.1333</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>10</td><td>1</td><td>2</td><td>&quot;Nasser, Mrs. N…</td><td>&quot;female&quot;</td><td>14.0</td><td>1</td><td>0</td><td>&quot;237736&quot;</td><td>30.0708</td><td>null</td><td>&quot;C&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name              ┆ … ┆ Ticket    ┆ Fare    ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 8           ┆ 0        ┆ 3      ┆ Palsson, Master.  ┆ … ┆ 349909    ┆ 21.075  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Gosta Leonard     ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 9           ┆ 1        ┆ 3      ┆ Johnson, Mrs.     ┆ … ┆ 347742    ┆ 11.1333 ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Oscar W           ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Elisabeth…       ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 10          ┆ 1        ┆ 2      ┆ Nasser, Mrs.      ┆ … ┆ 237736    ┆ 30.0708 ┆ null  ┆ C        │\n",
       "│             ┆          ┆        ┆ Nicholas (Adele   ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ Ach…              ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyarrow.dataset as ds\n",
    "\n",
    "dataset = ds.dataset(\n",
    "    gcs_parquet_file_path, \n",
    "    filesystem=fs,\n",
    "    format='parquet'\n",
    ")\n",
    "\n",
    "df = (\n",
    "    pl.scan_pyarrow_dataset(dataset)\n",
    "    .filter(pl.col('Age') <= 30)\n",
    "    .collect()\n",
    ")\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## BigQuery"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>180</td><td>0</td><td>3</td><td>&quot;Leonard, Mr. L…</td><td>&quot;male&quot;</td><td>36.0</td><td>0</td><td>0</td><td>&quot;LINE&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>264</td><td>0</td><td>1</td><td>&quot;Harrison, Mr. …</td><td>&quot;male&quot;</td><td>40.0</td><td>0</td><td>0</td><td>&quot;112059&quot;</td><td>0.0</td><td>&quot;B94&quot;</td><td>&quot;S&quot;</td></tr><tr><td>278</td><td>0</td><td>2</td><td>&quot;Parkes, Mr. Fr…</td><td>&quot;male&quot;</td><td>null</td><td>0</td><td>0</td><td>&quot;239853&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>303</td><td>0</td><td>3</td><td>&quot;Johnson, Mr. W…</td><td>&quot;male&quot;</td><td>19.0</td><td>0</td><td>0</td><td>&quot;LINE&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>414</td><td>0</td><td>2</td><td>&quot;Cunningham, Mr…</td><td>&quot;male&quot;</td><td>null</td><td>0</td><td>0</td><td>&quot;239853&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬─────────────────────────┬───┬────────┬──────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name                    ┆ … ┆ Ticket ┆ Fare ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---                     ┆   ┆ ---    ┆ ---  ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str                     ┆   ┆ str    ┆ f64  ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═════════════════════════╪═══╪════════╪══════╪═══════╪══════════╡\n",
       "│ 180         ┆ 0        ┆ 3      ┆ Leonard, Mr. Lionel     ┆ … ┆ LINE   ┆ 0.0  ┆ null  ┆ S        │\n",
       "│ 264         ┆ 0        ┆ 1      ┆ Harrison, Mr. William   ┆ … ┆ 112059 ┆ 0.0  ┆ B94   ┆ S        │\n",
       "│ 278         ┆ 0        ┆ 2      ┆ Parkes, Mr. Francis     ┆ … ┆ 239853 ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ \"Frank\"                 ┆   ┆        ┆      ┆       ┆          │\n",
       "│ 303         ┆ 0        ┆ 3      ┆ Johnson, Mr. William    ┆ … ┆ LINE   ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Cahoone Jr              ┆   ┆        ┆      ┆       ┆          │\n",
       "│ 414         ┆ 0        ┆ 2      ┆ Cunningham, Mr. Alfred  ┆ … ┆ 239853 ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Fleming                 ┆   ┆        ┆      ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴─────────────────────────┴───┴────────┴──────┴───────┴──────────┘"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "project = 'sandbox-366819'\n",
    "dataset = 'polars_cookbook_demo_yk'\n",
    "table = 'titanic_dataset'\n",
    "\n",
    "query = f'''\n",
    "    select *\n",
    "    from {project}.{dataset}.{table}\n",
    "'''\n",
    "credentials_file_path = 'YOUR_CREDENTIALS_FILE_PATH' \n",
    "uri = f'bigquery://{credentials_file_path}'\n",
    "\n",
    "df = pl.read_database_uri(query, uri, engine='connectorx')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PassengerId</th><th>Survived</th><th>Pclass</th><th>Name</th><th>Sex</th><th>Age</th><th>SibSp</th><th>Parch</th><th>Ticket</th><th>Fare</th><th>Cabin</th><th>Embarked</th></tr><tr><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>f64</td><td>i64</td><td>i64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>180</td><td>0</td><td>3</td><td>&quot;Leonard, Mr. L…</td><td>&quot;male&quot;</td><td>36.0</td><td>0</td><td>0</td><td>&quot;LINE&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>264</td><td>0</td><td>1</td><td>&quot;Harrison, Mr. …</td><td>&quot;male&quot;</td><td>40.0</td><td>0</td><td>0</td><td>&quot;112059&quot;</td><td>0.0</td><td>&quot;B94&quot;</td><td>&quot;S&quot;</td></tr><tr><td>278</td><td>0</td><td>2</td><td>&quot;Parkes, Mr. Fr…</td><td>&quot;male&quot;</td><td>null</td><td>0</td><td>0</td><td>&quot;239853&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>303</td><td>0</td><td>3</td><td>&quot;Johnson, Mr. W…</td><td>&quot;male&quot;</td><td>19.0</td><td>0</td><td>0</td><td>&quot;LINE&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>414</td><td>0</td><td>2</td><td>&quot;Cunningham, Mr…</td><td>&quot;male&quot;</td><td>null</td><td>0</td><td>0</td><td>&quot;239853&quot;</td><td>0.0</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬─────────────────────────┬───┬────────┬──────┬───────┬──────────┐\n",
       "│ PassengerId ┆ Survived ┆ Pclass ┆ Name                    ┆ … ┆ Ticket ┆ Fare ┆ Cabin ┆ Embarked │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---                     ┆   ┆ ---    ┆ ---  ┆ ---   ┆ ---      │\n",
       "│ i64         ┆ i64      ┆ i64    ┆ str                     ┆   ┆ str    ┆ f64  ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═════════════════════════╪═══╪════════╪══════╪═══════╪══════════╡\n",
       "│ 180         ┆ 0        ┆ 3      ┆ Leonard, Mr. Lionel     ┆ … ┆ LINE   ┆ 0.0  ┆ null  ┆ S        │\n",
       "│ 264         ┆ 0        ┆ 1      ┆ Harrison, Mr. William   ┆ … ┆ 112059 ┆ 0.0  ┆ B94   ┆ S        │\n",
       "│ 278         ┆ 0        ┆ 2      ┆ Parkes, Mr. Francis     ┆ … ┆ 239853 ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ \"Frank\"                 ┆   ┆        ┆      ┆       ┆          │\n",
       "│ 303         ┆ 0        ┆ 3      ┆ Johnson, Mr. William    ┆ … ┆ LINE   ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Cahoone Jr              ┆   ┆        ┆      ┆       ┆          │\n",
       "│ 414         ┆ 0        ┆ 2      ┆ Cunningham, Mr. Alfred  ┆ … ┆ 239853 ┆ 0.0  ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Fleming                 ┆   ┆        ┆      ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴─────────────────────────┴───┴────────┴──────┴───────┴──────────┘"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import polars as pl\n",
    "from google.cloud import bigquery\n",
    "\n",
    "client = bigquery.Client.from_service_account_json(credentials_file_path)\n",
    "query_job = client.query(query)\n",
    "rows = query_job.result()\n",
    "\n",
    "df = pl.from_arrow(rows.to_arrow())\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LoadJob<project=sandbox-366819, location=US, id=5c08f1f1-d163-4535-9867-b7a82cc5fba2>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import io \n",
    "\n",
    "with io.BytesIO() as stream:\n",
    "    df.write_csv(stream)\n",
    "    stream.seek(0)\n",
    "    job = client.load_table_from_file(\n",
    "        stream,\n",
    "        destination=f'{project}.{dataset}.titanic_dataset_v2',\n",
    "        project=project,\n",
    "        job_config=bigquery.LoadJobConfig(\n",
    "            autodetect=True,\n",
    "            source_format=bigquery.SourceFormat.CSV,\n",
    "        ),\n",
    "    )\n",
    "job.result() "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Snowflake"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PASSENGERID</th><th>SURVIVED</th><th>PCLASS</th><th>NAME</th><th>SEX</th><th>AGE</th><th>SIBSP</th><th>PARCH</th><th>TICKET</th><th>FARE</th><th>CABIN</th><th>EMBARKED</th></tr><tr><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1.0</td><td>0.0</td><td>3.0</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1.0</td><td>0.0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2.0</td><td>1.0</td><td>1.0</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1.0</td><td>0.0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3.0</td><td>1.0</td><td>3.0</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0.0</td><td>0.0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4.0</td><td>1.0</td><td>1.0</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1.0</td><td>0.0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5.0</td><td>0.0</td><td>3.0</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0.0</td><td>0.0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PASSENGERID ┆ SURVIVED ┆ PCLASS ┆ NAME              ┆ … ┆ TICKET    ┆ FARE    ┆ CABIN ┆ EMBARKED │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ f64         ┆ f64      ┆ f64    ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1.0         ┆ 0.0      ┆ 3.0    ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2.0         ┆ 1.0      ┆ 1.0    ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3.0         ┆ 1.0      ┆ 3.0    ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4.0         ┆ 1.0      ┆ 1.0    ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5.0         ┆ 0.0      ┆ 3.0    ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username = 'YOUR_USERNAME' \n",
    "password = 'YOUR_PASS' \n",
    "account = 'ndjydua-tdb43776'\n",
    "database = 'POLARS_COOKBOOK_DEMO_YK' \n",
    "warehouse = 'COMPUTE_WH'\n",
    "role = 'ACCOUNTADMIN'\n",
    "schema = 'SANDBOX' \n",
    "table = 'TITANIC_DATASET'\n",
    "\n",
    "query = f'select * from {table}'\n",
    "uri = f'snowflake://{username}:{password}@{account}/{database}/{schema}?warehouse={warehouse}&role={role}'\n",
    "\n",
    "df = pl.read_database_uri(\n",
    "    query,\n",
    "    uri,\n",
    "    engine='adbc'\n",
    ") \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PASSENGERID</th><th>SURVIVED</th><th>PCLASS</th><th>NAME</th><th>SEX</th><th>AGE</th><th>SIBSP</th><th>PARCH</th><th>TICKET</th><th>FARE</th><th>CABIN</th><th>EMBARKED</th></tr><tr><td>i16</td><td>i8</td><td>i8</td><td>str</td><td>str</td><td>f64</td><td>i8</td><td>i8</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PASSENGERID ┆ SURVIVED ┆ PCLASS ┆ NAME              ┆ … ┆ TICKET    ┆ FARE    ┆ CABIN ┆ EMBARKED │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i16         ┆ i8       ┆ i8     ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import snowflake.connector\n",
    "\n",
    "conn = snowflake.connector.connect(\n",
    "    user=username,\n",
    "    password=password,\n",
    "    account=account,\n",
    "    warehouse=warehouse,\n",
    "    database=database,\n",
    "    schema=schema\n",
    "    )\n",
    "\n",
    "(\n",
    "    pl.from_arrow(conn.cursor().execute(query).fetch_arrow_all())\n",
    "    .head()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>PASSENGERID</th><th>SURVIVED</th><th>PCLASS</th><th>NAME</th><th>SEX</th><th>AGE</th><th>SIBSP</th><th>PARCH</th><th>TICKET</th><th>FARE</th><th>CABIN</th><th>EMBARKED</th></tr><tr><td>i16</td><td>i8</td><td>i8</td><td>str</td><td>str</td><td>f64</td><td>i8</td><td>i8</td><td>str</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>1</td><td>0</td><td>3</td><td>&quot;Braund, Mr. Ow…</td><td>&quot;male&quot;</td><td>22.0</td><td>1</td><td>0</td><td>&quot;A/5 21171&quot;</td><td>7.25</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>2</td><td>1</td><td>1</td><td>&quot;Cumings, Mrs. …</td><td>&quot;female&quot;</td><td>38.0</td><td>1</td><td>0</td><td>&quot;PC 17599&quot;</td><td>71.2833</td><td>&quot;C85&quot;</td><td>&quot;C&quot;</td></tr><tr><td>3</td><td>1</td><td>3</td><td>&quot;Heikkinen, Mis…</td><td>&quot;female&quot;</td><td>26.0</td><td>0</td><td>0</td><td>&quot;STON/O2. 31012…</td><td>7.925</td><td>null</td><td>&quot;S&quot;</td></tr><tr><td>4</td><td>1</td><td>1</td><td>&quot;Futrelle, Mrs.…</td><td>&quot;female&quot;</td><td>35.0</td><td>1</td><td>0</td><td>&quot;113803&quot;</td><td>53.1</td><td>&quot;C123&quot;</td><td>&quot;S&quot;</td></tr><tr><td>5</td><td>0</td><td>3</td><td>&quot;Allen, Mr. Wil…</td><td>&quot;male&quot;</td><td>35.0</td><td>0</td><td>0</td><td>&quot;373450&quot;</td><td>8.05</td><td>null</td><td>&quot;S&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5, 12)\n",
       "┌─────────────┬──────────┬────────┬───────────────────┬───┬───────────┬─────────┬───────┬──────────┐\n",
       "│ PASSENGERID ┆ SURVIVED ┆ PCLASS ┆ NAME              ┆ … ┆ TICKET    ┆ FARE    ┆ CABIN ┆ EMBARKED │\n",
       "│ ---         ┆ ---      ┆ ---    ┆ ---               ┆   ┆ ---       ┆ ---     ┆ ---   ┆ ---      │\n",
       "│ i16         ┆ i8       ┆ i8     ┆ str               ┆   ┆ str       ┆ f64     ┆ str   ┆ str      │\n",
       "╞═════════════╪══════════╪════════╪═══════════════════╪═══╪═══════════╪═════════╪═══════╪══════════╡\n",
       "│ 1           ┆ 0        ┆ 3      ┆ Braund, Mr. Owen  ┆ … ┆ A/5 21171 ┆ 7.25    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Harris            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 2           ┆ 1        ┆ 1      ┆ Cumings, Mrs.     ┆ … ┆ PC 17599  ┆ 71.2833 ┆ C85   ┆ C        │\n",
       "│             ┆          ┆        ┆ John Bradley      ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Flor…            ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 3           ┆ 1        ┆ 3      ┆ Heikkinen, Miss.  ┆ … ┆ STON/O2.  ┆ 7.925   ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ Laina             ┆   ┆ 3101282   ┆         ┆       ┆          │\n",
       "│ 4           ┆ 1        ┆ 1      ┆ Futrelle, Mrs.    ┆ … ┆ 113803    ┆ 53.1    ┆ C123  ┆ S        │\n",
       "│             ┆          ┆        ┆ Jacques Heath     ┆   ┆           ┆         ┆       ┆          │\n",
       "│             ┆          ┆        ┆ (Li…              ┆   ┆           ┆         ┆       ┆          │\n",
       "│ 5           ┆ 0        ┆ 3      ┆ Allen, Mr.        ┆ … ┆ 373450    ┆ 8.05    ┆ null  ┆ S        │\n",
       "│             ┆          ┆        ┆ William Henry     ┆   ┆           ┆         ┆       ┆          │\n",
       "└─────────────┴──────────┴────────┴───────────────────┴───┴───────────┴─────────┴───────┴──────────┘"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.read_database(query, connection=conn)\n",
    "df.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
